ElasticSearch - Update a document and change value of a key

October 11, 2017

Introduction

I have few documents in the Elastic Search instance. And, due to some change in the code. I had to update the value of few keys in some of the documents.

Solution

Elastic Search has an update method, and we can use it like below:
POST index_name/type_name/<id of document>/_update
{
  "script": "ctx._source.<field> = 'the required value'"
}

Example

In my case, the input is like: ``` { "_index": "jira_create", "_type": "jira_created", "_id": "AV8KVD65tSgrIxXHHggk", "_score": 1, "_source": { "data": { "jiraId": "ABC-1234", "uniqueEntityId": "something was here", "attrs": { "versionId": "fg1pGsEQXLuTdQM1JeIR1CuAvp3K3jQu", "syncIssue": false } }, "createdAt": "2017-10-11T07:26:53.901Z" } } ```

Exact code

``` POST jira_create/jira_created/AV8KVD65tSgrIxXHHggk/_update { "script": "ctx._source.data.uniqueEntityId = 'my new value'" } ```

Thanks for reading.


Similar Posts

Latest Posts